package com.minio.project.Controller;

import com.minio.project.Service.ImgService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @PACKAGE_NAME: com.minio.project.Controller
 * @NAME: UploadImgController
 * @USER: ASUS
 * @DATE: 18/4/2025
 * @TIME: 下午3:07
 **/
@RestController
@RequestMapping("/img")
@Api(tags ="图片上传")
public class UploadImgController {

    @Autowired
    private ImgService imgService;

    @ApiOperation(
            value = "图片上传接口",
            notes = "该接口提供了图片上传的功能",
            consumes = MediaType.MULTIPART_FORM_DATA_VALUE,
            produces = MediaType.APPLICATION_JSON_UTF8_VALUE
    )
    @PostMapping("/upload")
    public String uploadImage(@RequestParam("file") MultipartFile file){
        return imgService.uploadImage(file);
    }

    @ApiOperation(
            value = "图片删除接口",
            notes = "该接口提供了图片删除的功能",
            consumes = MediaType.MULTIPART_FORM_DATA_VALUE,
            produces = MediaType.APPLICATION_JSON_UTF8_VALUE
    )
    @PostMapping("/delete")
    public void deleteImage(@RequestParam("name") String name){
        return imgService.deleteImage(name);
    }
}
